from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from options import options
from login_data import Login
'''
url = r'http://172.16.36.126/upload/'
driver = webdriver.Chrome(test_cases_webtours=test_cases_webtours)
driver.get(url)
# driver.maximize_window()      # 浏览器最大化

# 登录
driver.find_element(By.ID, 'ls_username').clear()  # 如果是文本框建议先清空一下内容
driver.find_element(By.ID, 'ls_username').send_keys('admin')
driver.find_element(By.ID, 'ls_password').clear()
driver.find_element(By.ID, 'ls_password').send_keys('123456')
sleep(3)
driver.find_element(By.XPATH, '//*[@id="lsform"]/div/div/table/tbody/tr[2]/td[3]/button/em').click()
sleep(3)
'''
url = r'http://172.16.36.126/upload/'
driver = webdriver.Chrome(options=options)
driver.get(url)
username = 'admin'
pwd = '123456'

login = Login(driver)
login.login(username, pwd)

# 发帖
driver.find_element(By.XPATH, '//*[@id="category_1"]/table/tbody/tr[2]/td[2]/h2/a').click()
driver.find_element(By.ID, 'newspecial').click()
driver.find_element(By.ID, 'subject').clear()
driver.find_element(By.ID, 'subject').send_keys('向下兼容')
# 嵌套页面（html页面嵌套html页面）无法直接定位，需要使用switch_to函数进入子页面
driver.switch_to.frame('e_iframe')
driver.find_element(By.XPATH, '/html/body').clear()
driver.find_element(By.XPATH, '/html/body').send_keys('朋友')
# 跳转到默认页面
driver.switch_to.default_content()
# # 跳转到父页面上一级页面
# driver.switch_to.parent_frame()
driver.find_element(By.ID, 'postsubmit').click()
sleep(3)

# 退出
# driver.find_element(By.LINK_TEXT, '退出').click()
# sleep(3)
login.logout()